<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	protected function _initConfig() 
	{
		/*
		*	Looking for base url
		*/
        $protocol = isset($_SERVER['HTTPS']) ? 'https' : 'http';
        $server = $_SERVER['HTTP_HOST'];
        $port = $_SERVER['SERVER_PORT'] != 80 ? ":{$_SERVER['SERVER_PORT']}" : '';
        $path = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/');
		define('HTTP_HOST', "$protocol://$server$port$path");
		/*
		*	Catching all Exceptions by ErrorController
		*/
		$front = Zend_Controller_Front::getInstance();
		$front->throwExceptions(false);
		
		$front->registerPlugin(new Obj_System_AclPlugin());
		$front->registerPlugin(new Obj_System_VirtualControllerPlugin());
		$front->registerPlugin(new Obj_System_MetaPlugin());
	}

	protected function _initConstants() {
		//User types
		include APPLICATION_PATH.'/constants/user-types.php';
		//System
		include APPLICATION_PATH.'/constants/system.php';
	}

	protected function _initDoctype()
    {
        $this->bootstrap('view');
        $view = $this->getResource('view');
        $view->doctype('HTML5');
    }
    
    protected function _initACL() {
		/*
		 * Creating system acl object
		 */
		if (true || !$oUser = Zend_Auth::getInstance()->getIdentity()) {
			$oUser = new stdClass();
			$oUser->usertype = USER_TYPE_GUEST;
			$oUser->ID = -1;
		}
		Zend_Registry::set('SYS_USER', $oUser);
    	$oACL = null;
		switch ($oUser->usertype) {
			case USER_TYPE_ADMIN: $oACL = new Obj_Acl_SiteAdmin(); break;
			case USER_TYPE_GUEST: 
			default: $oACL = new Obj_Acl_Base(); break;
		}
		$oACL->setRoles();
		$oACL->setResources();
		$oACL->setPrivilages();
		$oACL->setAcl();
    }
    
    protected function _initLocale() {
		$localeValue = 'ru';
		$locale = new Zend_Locale($localeValue);
		Zend_Registry::set('Zend_Locale', $locale);

		$translationFile = APPLICATION_PATH.'/../languages/ru.mo';
		$translate = new Zend_Translate('gettext', $translationFile, $localeValue);
		Zend_Registry::set('Zend_Translate', $translate);   
    }
}

